<?php
namespace Components\Account\User;

class Adapter {
  static private $__instance = [];
  static protected $_di;

  public function __construct($config = []) {
    self::$_di = $config['di'];
  }

  static public function getDI($key) {
    return self::$_di -> get($key);
  }

  static private function newClassName($key, $class_name, $parameter) {
    if(isset(self::$__instance[$key]) && !empty(self::$__instance[$key])) { return self::$__instance[$key]; }

    $className = __NAMESPACE__ . '\\' . $class_name;
    if(!class_exists($className)) { throw new \Exception($className . ' is non-existent.'); }

    return self::$__instance[$key] = new $className($parameter);
  }

  static public function getLogicInstance($parameter = []) {
    return self::newClassName('logic', 'Logic', $parameter);
  }

  static public function getModelInstance() {
    return self::$__instance['model'] = new Model();
  }

  static public function getServiceInstance($parameter = []) {
    return self::newClassName('service', 'Service', $parameter);
  }

  static public function getValidationInstance($parameter = []) {
    return self::newClassName('validation', 'Validation', $parameter);
  }

  static public function getFilterInstance($parameter = []) {
    return self::newClassName('filter', 'Filter', $parameter);
  }

  // Info Start
  static public function getInfoServiceInstance($parameter = []) {
    return self::newClassName('infoService', 'Info\\Service', $parameter);
  }

  static public function getInfoValidationInstance($parameter = []) {
    return self::newClassName('infoValidation', 'Info\\Validation', $parameter);
  }

  static public function getInfoFilterInstance($parameter = []) {
    return self::newClassName('infoFilter', 'Info\\Filter', $parameter);
  }

  // Wallet Start
  static public function getWalletServiceInstance($parameter = []) {
    return self::newClassName('walletService', 'Wallet\\Service', $parameter);
  }

  static public function getWalletValidationInstance($parameter = []) {
    return self::newClassName('walletValidation', 'Wallet\\Validation', $parameter);
  }

  static public function getWalletFilterInstance($parameter = []) {
    return self::newClassName('walletFilter', 'Wallet\\Filter', $parameter);
  }

  // Wallet Log Start
  static public function getWalletLogLogicInstance($parameter = []) {
    return self::newClassName('walletLogLogic', 'WalletLogLogic', $parameter);
  }

  static public function getWalletLogServiceInstance($parameter = []) {
    return self::newClassName('walletLogService', 'Wallet\\Log\\Service', $parameter);
  }

  // Achievement Start
  static public function getAchievementServiceInstance($parameter = []) {
    return self::newClassName('achievementService', 'Achievement\\Service', $parameter);
  }

  // Team Start
  static public function getTeamServiceInstance($parameter = []) {
    return self::newClassName('teamService', 'Team\\Service', $parameter);
  }
  
}
